const state = {
  userId: null,
  username: null,
  token: null
}

const mutations = {
  setUserId (state, userId) {
    state.userId = userId
  },
  setUsername (state, username) {
    state.username = username
  },
  setToken (state, token) {
    state.token = token
  },
  clearUserInfo (state) {
    state.userId = null
  }
}

const actions = {
  setUserInfo ({ commit }, userInfo) {
    commit('setUserId', userInfo.userId)
    commit('setUsername', userInfo.username)
    commit('setToken', userInfo.token)
  }
}
const getters = {
  getUserInfo: state => {
    return {
      userId: state.userId,
      username: state.username,
      token: state.token
    }
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
